package com.bdqn.jiang.Service.impl;

import com.bdqn.jiang.Service.BaseService;
import com.bdqn.jiang.entity.Leibiao;
import com.bdqn.jiang.utils.ServiceFactory;

import java.io.File;
import java.util.List;
import java.util.Scanner;

public class GetNovelsService implements BaseService {
    Scanner sc=new Scanner(System.in);
    int k=0;

    @Override
    public void execute(List list) {

        System.out.println("---------------------------小说列表结束------------------------");
        System.out.println("0.返回上一级菜单");
        System.out.println("-1.上传小说");
        System.out.println("请输入小说序号阅读");
        int shuru=sc.nextInt();
        if (shuru==0){
            BaseService baseService = ServiceFactory.getService("leix");
            baseService.execute(list);
        }else if(shuru==-1){
            for (;;) {
                System.out.println("请输入小说名称");
                String NSname = sc.next();
                System.out.println("请输入作者");
                String Uname = sc.next();
                System.out.println("请输入简介");
                String Ujianjie = sc.next();

                for (; ; ) {

                    System.out.println("请输入上传的.txt(请注意路径用/或\\):");
                    String lj = sc.next();

                    File file = new File(lj);

                    if (!file.exists()) {
                        System.out.println("路径不存在，请重新上传");
                        continue;
                    }
                    Leibiao leibiao = new Leibiao();


                    leibiao.setUsername(NSname);
                    leibiao.setName(Uname);
                    leibiao.setJianjie(Ujianjie);
                    list.add(leibiao);
                    System.out.println("添加成功");

                    for (int i = 0; i < list.size(); i++) {
                        Leibiao leibiao2 = (Leibiao) list.get(i);
                        System.out.println((i + 1) + "\t"+ leibiao2.getUsername() + "\t" + leibiao2.getName() + "\t" + leibiao2.getJianjie());
                    }

                    System.out.println("***********");
                    System.out.println("0.返回上一级菜单");
                    System.out.println("1.继续上传");



                    break;
                }
                int xz=sc.nextInt();
                if (xz==0){
                    break;
                }else if (xz==1){
                    continue;
                }else{
                    System.out.println("您输入有误,请重新输入");
                }
            }

                }



        }


    }
